package org.smr.ministore.micro;

import java.util.List;

import org.blade.utils.IdGenUtils;
import org.smr.ministore.dao.GoodsTypeMapper;
import org.smr.ministore.entities.GoodsType;
import org.smr.ministore.entities.vo.Assign2OrgansVO;
import org.smr.ministore.service.GoodsTypeService;
import org.blade.service.base.AbstractService;

import org.blade.utils.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
public class GoodsTypeMicroService extends AbstractService<Long, GoodsType> implements GoodsTypeService {

    @Resource(name="goodsTypeServiceImpl")
    private GoodsTypeService goodsTypeService;

    @Autowired
    public GoodsTypeMicroService(GoodsTypeMapper mapper) {
        super(mapper);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/GoodsType/batchSave")
    public int batchSave(@RequestBody List<GoodsType> entities) {
        return goodsTypeService.batchSave(entities);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/GoodsType/batchModify")
    public int batchModify(List<GoodsType> entities) {
        return goodsTypeService.batchModify(entities);
    }


    @ResponseBody
    @RequestMapping(method = RequestMethod.PUT, value = "/GoodsType/save")
    public int save(@RequestBody GoodsType entity) {

        return goodsTypeService.save(entity);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.PATCH, value = "/GoodsType/updateById")
    public int updateById(@RequestBody GoodsType id) {
        return goodsTypeService.updateById(id);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/GoodsType/queryById/{id}")
    public GoodsType queryById(@PathVariable("id") Long id) {
        return goodsTypeService.queryById(id);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.DELETE, value = "/GoodsType/deleteById/{id}")
    public int deleteById(@PathVariable("id") Long id) {
        return goodsTypeService.deleteById(id);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/GoodsType/paginate/{pageSize}/{pageNum}")
    public Pager<GoodsType> paginate(GoodsType entity, @PathVariable("pageSize") Long pageSize, @PathVariable("pageNum") Long pageNum) {
        return goodsTypeService.paginate(entity, pageSize, pageNum);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/GoodsType/getGoodsTypeTree")
    public List<GoodsType> getGoodsTypeTree(@RequestBody GoodsType goodsType) {
        return goodsTypeService.getGoodsTypeTree(goodsType);
    }

    @Override
    @ResponseBody
    @RequestMapping(method = RequestMethod.DELETE, value = "/GoodsType/deleteByIdLogical/{id}")
    public int deleteByIdLogical(@PathVariable("id") Long id) {
        return goodsTypeService.deleteByIdLogical(id);
    }

    @Override
    @ResponseBody
    @RequestMapping(method = RequestMethod.DELETE, value = "/GoodsType/getGoodsTypeTree")
    public int removeById(@RequestBody GoodsType id) {
        return 0;
    }

    @Override
    @ResponseBody
    @RequestMapping(method = RequestMethod.DELETE, value = "/GoodsType/assignToOrgans")
    public int assignToOrgans(@RequestBody Assign2OrgansVO assign2Organs) {
        return goodsTypeService.assignToOrgans(assign2Organs);
    }

    @Override
    public Long getId() {
        return IdGenUtils.getNextLongId();
    }
}
